package com.yj.suncity.setting;

import org.json.JSONObject;

import com.yj.suncity.R;
import com.yj.suncity.async.AsyncTaskUtil;
import com.yj.suncity.async.AsyncTaskUtil.ResultCallBack;
import com.yj.suncity.constant.URLCon;
import com.yj.suncity.utis.ToastUtil;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;

public class HelpActivity extends Activity {
	private Context context;
	private WebView view;
	private ImageView imageView;
	private ScrollView scrollView;
	private int mWidth;
	private int flag;//1,首页通知公告-》当前
	private String content;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_about_us);
		context = this;
		mWidth = getResources().getDisplayMetrics().widthPixels;
		content=getIntent().getStringExtra("content");
		flag=getIntent().getIntExtra("flag", -1);
		findView();
		// initData();
	}

	private void findView() {

		if (flag==1) {
			((TextView) findViewById(R.id.txt_title_name)).setText("详情");
			view = (WebView) findViewById(R.id.webView1);
			view.setVisibility(View.VISIBLE);
			WebSettings settings = view.getSettings();
			settings.setUseWideViewPort(false);// 设置webview 推荐使用的串口。
			settings.setLoadWithOverviewMode(true);// 设置webview加载页面的方式
			settings.setJavaScriptEnabled(true);// 要与javascript交互
			// settings.setAllowFileAccess(true);//要访问本地文件
			settings.setSupportZoom(true);
			// settings.setBuiltInZoomControls(true);
			// view.setInitialScale(39);
			view.setBackgroundColor(0);// 设置透明颜色
			settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
			
			view.loadDataWithBaseURL(URLCon.HOST, content,
					"text/html", "utf-8", "");
		} else {
			((TextView) findViewById(R.id.txt_title_name)).setText("帮助");
			scrollView=(ScrollView) findViewById(R.id.scroll_img);
			scrollView.setVisibility(View.VISIBLE);
			
			imageView = (ImageView) findViewById(R.id.img_help);
			imageView.setLayoutParams(new ScrollView.LayoutParams(mWidth,
					mWidth * 1729 / 640));
			imageView.setImageResource(R.drawable.help_picture);
		}

		
		


	}

	private void initData() {
		String path = URLCon.设置 + "?action=help";
		AsyncTaskUtil asyncTaskUtil = new AsyncTaskUtil(context, null, null,
				false, null, true, "正在加载......", new ResultCallBack() {
					@Override
					public void JSONResult(JSONObject jsonObject) {
						if (jsonObject.optString("success").equals("1")) {
							String context = jsonObject.optString("context");
							view.loadDataWithBaseURL(URLCon.HOST, context,
									"text/html", "utf-8", "");
						} else {
							ToastUtil.ShowToast(context,
									jsonObject.optString("msg"));
						}
					}
				});
		asyncTaskUtil.execute(path);
	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btnHeadBack:
			this.finish();
			break;

		default:
			break;
		}
	}

}
